package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.WxCampFacility;
import com.ruoyi.wechat.domain.WxCampFacilityVo;
import com.ruoyi.wechat.domain.WxFacilityType;
import com.ruoyi.wechat.service.IWxFacilityService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>ClassName : 微信小程序提供服务设施接口</p>
 * <p>Description : </p>
 *
 * @author 孙伟光
 * @version 1.0
 * @date 2024/7/26 8:30
 */
@Api(value = "微信小程序API-服务设施管理", tags = {"微信小程序API-服务设施管理"})
@RestController
@RequestMapping("/wechat/facility")
public class WxFacilityController extends BaseController {

    @Autowired
    private IWxFacilityService wxFacilityService;

    @ApiOperation(value = "获取服务设施类型以及对应的服务设施数据列表", response = WxFacilityType.class)
    @GetMapping("/list")
    public AjaxResult list() {
        List<WxFacilityType> list  = wxFacilityService.facilityTypeList();
        return success(list);
    }

    @ApiOperation(value = "根据营地Id查询该营地的服务设施列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "campId", value = "营地Id", required = true, dataType = "String", paramType = "query"),
    })
    @GetMapping("/getInfo/{campId}")
    public AjaxResult getInfo(@PathVariable("campId") String campId) {
        if (campId == null) {
            return error("营地Id不能为空");
        }
        List<WxFacilityType> list = wxFacilityService.campFacilityListByCampId(campId);
        return success(list);
    }

    @ApiOperation(value = "根据营地Id和服务设施Id集合完成批量添加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "campId", value = "营地Id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "facilityIds", value = "服务设施Id集合", required = true, dataType = "String[]", paramType = "query")
    })
    @Log(title = "微信小程序API-服务设施管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WxCampFacilityVo wxCampFacilityVo){
        if (wxCampFacilityVo.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (wxCampFacilityVo.getFacilityIds() == null) {
            return error("服务设施Id不能为空");
        }
        return toAjax(wxFacilityService.insertCampFacility(wxCampFacilityVo.getCampId(), wxCampFacilityVo.getFacilityIds()));
    }

    @ApiOperation(value = "根据营地Id完成删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "campId", value = "营地Id", required = true, dataType = "String", paramType = "query"),
    })
    @Log(title = "微信小程序API-服务设施管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{campId}")
    public AjaxResult delete(@PathVariable("campId") String campId){
        if (campId == null) {
            return error("营地Id不能为空");
        }
        return toAjax(wxFacilityService.deleteCampFacilityByCampId(campId));
    }
}
